package timer

import (
	"finance/db"
	"finance/historyImport"
	"fmt"
	"github.com/robfig/cron"
	"strings"
	"time"
)

func TimerImportHistory() {
	go func() {
		crontab := cron.New()
		crontab.AddFunc("0 0 12 * * ?", test) // 每天 8:20:00 定时执行 myfunc 函数
		crontab.Start()
	}()
}

func test() {
	db := db.InitMysqlDb()
	date := strings.Replace(time.Now().String()[0:10], "-", "", -1)
	insertCount, failCount := historyImport.ImportHistory("0000001", date, date)
	fmt.Println("%s %s %s", date, insertCount, failCount)
	defer db.Close()
}
